function initMap() {
	const AK = "yiwjIC1eeztYhlF1Hnv0OrmbxERx6yrJ" //你的AK
	const BMap_URL =
		"https://api.map.baidu.com/api?v=2.0&ak=" +
		AK +
		"&s=1&callback=onBMapCallback"
	return new Promise(resolve => {
		// 如果已加载直接返回
		if (typeof BMap !== "undefined") {
			resolve(BMap)
			return true
		}
		// 百度地图异步加载回调处理

		window.onBMapCallback = function () {
			resolve(BMap)
		}
		// let getCurrentCityName = function () {
		//   return new Promise(function (resolve, reject) {
		//     let myCity = new BMap.LocalCity()
		//     myCity.get(function (result) {
		//       resolve(result.name)
		//     })
		//   })
		// }
		// 插入script脚本
		let scriptNode = document.createElement("script")
		scriptNode.setAttribute("type", "text/javascript")
		scriptNode.setAttribute("src", BMap_URL)
		document.body.appendChild(scriptNode)
	})
}

// 定位
function getCity() {
	initMap().then(BMap => {
		const geolocation = new BMapGL.Geolocation()
		geolocation.getCurrentPosition(
			position => {
				let city1 = position.address.city //获取城市信息
				//获取省份信息
				// let province = position.address.province;
				console.log(city1)
				// console.log(province)
			},
			e => {
				console.log(e)
				console.log("定位失败")
			},
			{
				provider: "baidu"
			}
		)
	})
}
